function getUrlParam(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
	var r = window.location.search.substr(1).match(reg);  //匹配目标参数
	if (r != null) return unescape(r[2]); return null; //返回参数值
}
function login(formdata){
	var localObj = window.location;
	var contextPath = localObj.pathname.split("/")[1];
	var basePath = localObj.protocol+"//"+localObj.host+"/"+contextPath+"/";
	$.ajax({
		type:"post",
		url:basePath+"log/auth",
		data:JSON.stringify(formdata),
		datatype:'JSON',
		async:true,
		success:function(resultString){
			var result=eval(resultString);
			if(result.result_code==200){
				$.cookie('permission', result.data.permission, { expires: 7 });
				if(result.data.id){
					$.cookie('id', result.data.id, { expires: 7 });
				}
				if(result.data.name){
					$.cookie('name', result.data.name, { expires: 7 });
				}
				if(result.data.menber==0||result.data.menber==1){
					$.cookie('menber', result.data.menber, { expires: 7 });
				}
				window.location.href=basePath+"html/index.html";
			} else if(result.result_code==1014){
				alert("该账号错误");
			} else{
				alert("该账号或密码错误");
			}

		},
		error:function(rsultString){
			alert("错误");
			window.location.href=basePath+"html/login.html";
		}
	});
}
function logout(){
	var localObj = window.location;
	var contextPath = localObj.pathname.split("/")[1];
	var basePath = localObj.protocol+"//"+localObj.host+"/"+contextPath+"/";
	$.ajax({
		type:"post",
		url:basePath+"log/out",
		async:true,
		success:function(resultString){
			$.cookie("id", "", {expires: -1});
			$.cookie("name", "", {expires: -1});
			$.cookie("permission", "", {expires: -1});
			window.location.href=basePath+"html/login.html";
		},
		error:function(rsultString){
			$.cookie("id", "", {expires: -1});
			$.cookie("name", "", {expires: -1});
			$.cookie("permission", "", {expires: -1});
			window.location.href=basePath+"html/login.html";
		}
	});
}
function openMenber(){
	var localObj = window.location;
	var contextPath = localObj.pathname.split("/")[1];
	var basePath = localObj.protocol+"//"+localObj.host+"/"+contextPath+"/";
	if(confirm("确定开通会员?")){
		$.ajax({
			type:"post",
			url:basePath+"user/openMenber",
			data:'{"id":"'+$.cookie("id")+'"}',
			async:true,
			success:function(resultString){
				var result = eval(resultString);
				if(result.result_code==200){
					alert("开通成功");
					window.location.href=basePath+"html/index.html";
				}else if(result.result_code==1013){
					alert("余额不足");
				}else if (result.result_code==1014){
					alert("无法重复开通会员");
				}
			},
			error:function(rsultString){
				window.location.href=basePath+"html/index.html";
			}
		});
	}
}
function sendmail_register(){
	var localObj = window.location;
	var contextPath = localObj.pathname.split("/")[1];
	var basePath = localObj.protocol+"//"+localObj.host+"/"+contextPath+"/";
	$("#submit").empty();
	$("#submit").append('<span class="bigger-110">注册</span><i class="ace-icon fa fa-arrow-right icon-on-right"></i>');
	$("#submit").attr("onclick","register()");
	$.ajax({
		type:"post",
		url:basePath+"validateCode/sendmail",
		data:JSON.stringify($("#register").serializeObject()),
		async:true,
		success:function(resultString){
			var result = eval(resultString);
			if(result.result_code==200){
				alert("发送成功");
			} else {
				alert("错误");
			}
		},
		error:function(rsultString){
			alert("错误");
			window.location.href=basePath+"html/login.html";
		}
	});
	return false;
}
function sendmail_resetting(){
	var localObj = window.location;
	var contextPath = localObj.pathname.split("/")[1];
	var basePath = localObj.protocol+"//"+localObj.host+"/"+contextPath+"/";
	$.ajax({
		type:"post",
		url:basePath+"validateCode/sendmail",
		data:JSON.stringify($("#resetting").serializeObject()),
		async:true,
		success:function(resultString){
			var result = eval(resultString);
			if(result.result_code==200){
				alert("发送成功");
				$("#resettingSubmit").empty();
				$("#resettingSubmit").append('<span class="bigger-110">输入验证码</span><i class="ace-icon fa fa-arrow-right icon-on-right"></i>');
				$("#resettingSubmit").attr("onclick","resetting()");
				$("#userId").val(result.data);
			} else {
				alert("错误");
			}
		},
		error:function(rsultString){
			alert("错误");
			window.location.href=basePath+"html/login.html";
		}
	});
	return false;
}
function resetting(){
	var localObj = window.location;
	var contextPath = localObj.pathname.split("/")[1];
	var basePath = localObj.protocol+"//"+localObj.host+"/"+contextPath+"/";
	$.ajax({
		type:"post",
		url:basePath+"validateCode/code",
		data:JSON.stringify($("#resetting").serializeObject()),
		async:true,
		success:function(resultString){
			var result = eval(resultString);
			if(result.result_code==200){
				alert("验证通过");
				$("#resettingInput").empty();
				$("#resettingInput").append('<label class="block clearfix"> <span class="block input-icon input-icon-right"> <input type="password" class="form-control" placeholder="输入密码" /> <i class="ace-icon fa fa-envelope"></i> </span> </label> <label class="block clearfix"> <span class="block input-icon input-icon-right"> <input type="password" name="password" class="form-control" placeholder="再次输入密码" /> <i class="ace-icon fa fa-envelope"></i> </span> </label> <div class="clearfix"> <button type="button" id="resettingSubmit" onclick="resettingPassword()" class="width-35 pull-right btn btn-sm btn-danger"> <i class="ace-icon fa fa-lightbulb-o"></i> <span class="bigger-110">重置密码</span> </button> </div>');
			} else {
				alert("错误");
			}
		},
		error:function(rsultString){
			alert("错误");
			window.location.href=basePath+"html/login.html";
		}
	});
	return false;
}
function resettingPassword(){
	var localObj = window.location;
	var contextPath = localObj.pathname.split("/")[1];
	var basePath = localObj.protocol+"//"+localObj.host+"/"+contextPath+"/";
	$.ajax({
		type:"post",
		url:basePath+"user/change",
		data:JSON.stringify($("#resetting").serializeObject()),
		async:true,
		success:function(resultString){
			var result = eval(resultString);
			if(result.result_code==200){
				alert("请重新登录");
				window.location.href=basePath+"html/login.html";
			} else {
				alert("错误");
			}
		},
		error:function(rsultString){
			alert("错误");
			window.location.href=basePath+"html/login.html";
		}
	});
	return false;
}
function register(){
	var localObj = window.location;
	var contextPath = localObj.pathname.split("/")[1];
	var basePath = localObj.protocol+"//"+localObj.host+"/"+contextPath+"/";
	$.ajax({
		type:"post",
		url:basePath+"user/add",
		data:JSON.stringify($("#register").serializeObject()),
		async:true,
		success:function(resultString){
			var result = eval(resultString);
			if(result.result_code==200){
				$.cookie('permission', result.data.permission, { expires: 7 });
				if(result.data.id){
					$.cookie('id', result.data.id, { expires: 7 });
				}
				if(result.data.name){
					$.cookie('name', result.data.name, { expires: 7 });
				}
				window.location.href=basePath+"html/index.html";
			} else {
				alert("错误");
			}
		},
		error:function(rsultString){
			alert("错误");
			window.location.href=basePath+"html/login.html";
		}
	});
	return false;
}
function add_one_book(){
	var localObj = window.location;
	var contextPath = localObj.pathname.split("/")[1];
	var basePath = localObj.protocol+"//"+localObj.host+"/"+contextPath+"/";
	$.ajax({
		type:"post",
		url:basePath+"book/addbookandfile",
		data:JSON.stringify($("#addform").serializeObject()),
		async:true,
		success:function(resultString){
			var result = eval(resultString);
			if(result.result_code==200){
				window.location.href=basePath+"html/book.html";
			} else {
				alert("错误");
			}
		},
		error:function(rsultString){
			alert("错误");
			window.location.href=basePath+"html/book.html";
		}
	});
	return false;
}
function change_one_book(){
	var localObj = window.location;
	var contextPath = localObj.pathname.split("/")[1];
	var basePath = localObj.protocol+"//"+localObj.host+"/"+contextPath+"/";
	$.ajax({
		type:"post",
		url:basePath+"book/change",
		data:JSON.stringify($("#changeform").serializeObject()),
		async:true,
		success:function(resultString){
			var result = eval(resultString);
			if(result.result_code==200){
				window.location.href=basePath+"html/book.html";
			} else {
				alert("错误");
			}
		},
		error:function(rsultString){
			alert("错误");
			window.location.href=basePath+"html/book.html";
		}
	});
	return false;
}
function book_detail(){
	var localObj = window.location;
	var contextPath = localObj.pathname.split("/")[1];
	var basePath = localObj.protocol+"//"+localObj.host+"/"+contextPath+"/";
	var id =getUrlParam("id");
	var sectionId =getUrlParam("sectionId");
	var bookTemp = new Object();
	var sectionIdTemp = new Object();
	$.ajax({
		type:"post",
		url:basePath+"book/getbycondition",
		data:'{"id":"'+id+'"}',
		async:false,
		success:function(resultString){
			var result = eval(resultString);
			if(result.result_code==200){
				var booklist=new Array();
				booklist=eval(result.data.rows);
				bookTemp.id=booklist[0].id;
				bookTemp.name=booklist[0].name;
				bookTemp.publishPeople=booklist[0].publishPeople;
				bookTemp.publishHoush=booklist[0].publishHoush;
				bookTemp.publishTime=booklist[0].publishTime;
				bookTemp.menberOnly=booklist[0].menberOnly;
			} else {
				alert("错误");
			}
		}
	});
	$.ajax({
		type:"post",
		url:basePath+"section/getbycondition",
		data:'{"bookId":"'+bookTemp.id+'"}',
		async:false,
		success:function(resultString){
			var result = eval(resultString);
			if(result.result_code==200){
				var sectionlist=new Array();
				sectionlist=eval(result.data.rows);
				sectionIdTemp.id=sectionlist[0].id;
			}
		}
	});
	if(sectionId!=null){
		$.ajax({
			type:"post",
			url:basePath+"section/getcontent",
			data:'{"type":"1","id":"'+sectionId+'"}',
			datatype:'JSON',
			async:false,
			success:function(resultString){
				var result = eval(resultString);
				if(result.result_code==200){
					var sectionlist=new Array();
					sectionlist=eval(result.data.rows);
					$("#title").empty();
					$(".lead").empty();
					$.each(sectionlist, function (i, section) {
						var menber = $.cookie('menber');
						if(bookTemp.menberOnly==1){
							if($.cookie('menber')==0){
								alert("本书为会员专享，请开通会员！");
								window.location.href=basePath+"html/book.html";
							}
						}
						$(".lead").load('http://'+localObj.hostname+'/alex_images/bookfile'+section.url);
					});
					$("#title").append(bookTemp.name+'<small><i class="ace-icon fa fa-angle-double-right"></i>章节名：'+sectionlist[0].name+'  作者：'+bookTemp.publishPeople+'  出版社：'+bookTemp.publishHoush+'  出版时间：'+bookTemp.publishTime+'</small>');
				} else {
					alert("错误");
				}
			}
		});
		$.ajax({
			type:"post",
			url:basePath+"readingLog/changeradinglogsection",
			data:'{"bookId":"'+id+'","peruserId":"'+$.cookie('id')+'","sectionId":"'+sectionId+'"}',
			async:false,
			success:function(resultString){

			}
		});
	} else {
		$.ajax({
			type:"post",
			url:basePath+"section/getcontent",
			data:'{"type":"0","bookId":"'+id+'"}',
			datatype:'JSON',
			async:false,
			success:function(resultString){
				var result = eval(resultString);
				if(result.result_code==200){
					var sectionlist=new Array();
					sectionlist=eval(result.data.rows);
					$("#title").empty();
					$(".lead").empty();
					$.each(sectionlist, function (i, section) {
						var menber = $.cookie('menber');
						if(bookTemp.menberOnly==1){
							if($.cookie('menber')==0){
								alert("本书为会员专享，请开通会员！");
								window.location.href=basePath+"html/book.html";
							}
						}
					});
					$(".lead").load('http://'+localObj.hostname+'/alex_images/bookfile'+sectionlist[0].url);
					$("#title").append(bookTemp.name+'<small><i class="ace-icon fa fa-angle-double-right"></i>章节名：'+sectionlist[0].name+'  作者：'+bookTemp.publishPeople+'  出版社：'+bookTemp.publishHoush+'  出版时间：'+bookTemp.publishTime+'</small>');
				} else {
					alert("错误");
				}
			}
		});
		$.ajax({
			type:"post",
			url:basePath+"readingLog/changeradinglogsection",
			data:'{"bookId":"'+id+'","peruserId":"'+$.cookie('id')+'","sectionId":"'+sectionIdTemp.id+'"}',
			async:false,
			success:function(resultString){
				
			}
		});
	}
}
function add_one_book_type(){
	var localObj = window.location;
	var contextPath = localObj.pathname.split("/")[1];
	var basePath = localObj.protocol+"//"+localObj.host+"/"+contextPath+"/";
	$.ajax({
		type:"post",
		url:basePath+"bookType/add",
		data:JSON.stringify($("#addform").serializeObject()),
		async:true,
		success:function(resultString){
			var result = eval(resultString);
			if(result.result_code==200){
				window.location.href=basePath+"html/bookType.html";
			} else {
				alert("错误");
			}
		},
		error:function(rsultString){
			alert("错误");
			window.location.href=basePath+"html/bookType.html";
		}
	});
	return false;
}
function change_one_book_type(){
	var localObj = window.location;
	var contextPath = localObj.pathname.split("/")[1];
	var basePath = localObj.protocol+"//"+localObj.host+"/"+contextPath+"/";
	$.ajax({
		type:"post",
		url:basePath+"bookType/change",
		data:JSON.stringify($("#changeform").serializeObject()),
		async:true,
		success:function(resultString){
			var result = eval(resultString);
			if(result.result_code==200){
				window.location.href=basePath+"html/bookType.html";
			} else {
				alert("错误");
			}
		},
		error:function(rsultString){
			alert("错误");
			window.location.href=basePath+"html/bookType.html";
		}
	});
	return false;
}
function add_one_manager(){
	var localObj = window.location;
	var contextPath = localObj.pathname.split("/")[1];
	var basePath = localObj.protocol+"//"+localObj.host+"/"+contextPath+"/";
	$.ajax({
		type:"post",
		url:basePath+"manager/add",
		data:JSON.stringify($("#addform").serializeObject()),
		async:true,
		success:function(resultString){
			var result = eval(resultString);
			if(result.result_code==200){
				window.location.href=basePath+"html/manager.html";
			} else {
				alert("错误");
			}
		},
		error:function(rsultString){
			alert("错误");
			window.location.href=basePath+"html/bookType.html";
		}
	});
	return false;
}
function change_one_manager(){
	var localObj = window.location;
	var contextPath = localObj.pathname.split("/")[1];
	var basePath = localObj.protocol+"//"+localObj.host+"/"+contextPath+"/";
	$.ajax({
		type:"post",
		url:basePath+"manager/change",
		data:JSON.stringify($("#changeform").serializeObject()),
		async:true,
		success:function(resultString){
			var result = eval(resultString);
			if(result.result_code==200){
				window.location.href=basePath+"html/manager.html";
			} else {
				alert("错误");
			}
		},
		error:function(rsultString){
			alert("错误");
			window.location.href=basePath+"html/manager.html";
		}
	});
	return false;
}
function change_one_user(){
	var localObj = window.location;
	var contextPath = localObj.pathname.split("/")[1];
	var basePath = localObj.protocol+"//"+localObj.host+"/"+contextPath+"/";
	$.ajax({
		type:"post",
		url:basePath+"user/change",
		data:JSON.stringify($("#changeform").serializeObject()),
		async:true,
		success:function(resultString){
			var result = eval(resultString);
			if(result.result_code==200){
				window.location.href=basePath+"html/user.html";
			} else {
				alert("错误");
			}
		},
		error:function(rsultString){
			alert("错误");
			window.location.href=basePath+"html/user.html";
		}
	});
	return false;
}
function change_one_manager_userinfo(){
	var localObj = window.location;
	var contextPath = localObj.pathname.split("/")[1];
	var basePath = localObj.protocol+"//"+localObj.host+"/"+contextPath+"/";
	$.ajax({
		type:"post",
		url:basePath+"manager/change",
		data:JSON.stringify($("#changeform").serializeObject()),
		async:true,
		success:function(resultString){
			var result = eval(resultString);
			if(result.result_code==200){
				alert("本次修改将在下次登录时生效");
				window.location.href=basePath+"html/userInfo.html";
			} else {
				alert("错误");
			}
		},
		error:function(rsultString){
			alert("错误");
			window.location.href=basePath+"html/userInfo.html";
		}
	});
	return false;
}
function change_one_user_userinfo(){
	var localObj = window.location;
	var contextPath = localObj.pathname.split("/")[1];
	var basePath = localObj.protocol+"//"+localObj.host+"/"+contextPath+"/";
	$.ajax({
		type:"post",
		url:basePath+"user/change",
		data:JSON.stringify($("#changeform").serializeObject()),
		async:true,
		success:function(resultString){
			var result = eval(resultString);
			if(result.result_code==200){
				alert("本次修改将在下次登录时生效");
				window.location.href=basePath+"html/userInfo.html";
			} else {
				alert("错误");
			}
		},
		error:function(rsultString){
			alert("错误");
			window.location.href=basePath+"html/userInfo.html";
		}
	});
	return false;
}
function user_info(){
	var localObj = window.location;
	var contextPath = localObj.pathname.split("/")[1];
	var basePath = localObj.protocol+"//"+localObj.host+"/"+contextPath+"/";
	var permission = $.cookie('permission');
	var str = $.cookie('id');
	var url;
	if(permission==1){
		url="user";
		$.ajax({
			type:"post",
			url:basePath+url+"/getbycondition",
			data:'{"id":"'+str+'"}',
			async:true,
			success:function(resultString){
				var result = eval(resultString);
				if(result.result_code==200){
					var resultList=new Array();
					resultList=eval(result.data.rows);
					$("#userInfos").empty();
					$.each(resultList, function (i, user) {
						if(user.menber==0){
							user.menber="不是会员";
						}else{
							user.menber="是会员";
						}
						$("#userInfos").append('<div id="change"> <form id="changeform" class="form-horizontal" role="form"> <input id="change_id_input" name="id" type="text" value="'+user.id+'" style="display:none;" /> <div class="form-group"> <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 编号：</label> <div class="col-sm-9"> <input disabled="disabled" id="change_id" type="text" class="col-xs-10 col-sm-5" value="'+user.id+'" /> </div> </div> <div class="form-group"> <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 账号：</label> <div class="col-sm-9"> <input readonly="" id="change_account" type="text" class="col-xs-10 col-sm-5" value="'+user.account+'" /> </div> </div><div class="form-group"> <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 是否为会员：</label> <div class="col-sm-9"> <input readonly="" id="change_menber" type="text" class="col-xs-10 col-sm-5" value="'+user.menber+'" /> </div> </div> <div class="form-group"> <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 密码：</label> <div class="col-sm-9"> <input type="text" id="change_phone" name="password" value="'+user.password+'" placeholder="输入密码" class="col-xs-10 col-sm-5" /> </div> </div> <div class="form-group"> <label class="col-sm-3 control-label no-padding-right" for="form-field-1-1">姓名： </label> <div class="col-sm-9"> <input type="text" id="change_name" name="name" value="'+user.name+'" placeholder="输入姓名" class=" col-xs-10 col-sm-5" /> </div> </div> <div class="form-group"> <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 余额：</label> <div class="col-sm-9"> <input readonly="" id="change_balance" type="text" class="col-xs-10 col-sm-5" value="'+user.balance+'" /> </div> </div> <div class="form-group"> <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 手机号：</label> <div class="col-sm-9"> <input type="text" id="change_phone" name="phone" value="'+user.phone+'" placeholder="输入手机号" class="col-xs-10 col-sm-5" /> </div> </div> <div class="form-group"> <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 邮箱：</label> <div class="col-sm-9"> <input type="text" id="change_mail" name="mail" value="'+user.mail+'" placeholder="输入邮箱" class="col-xs-10 col-sm-5" /> </div> </div> <div class="clearfix form-actions"> <div class="col-md-offset-3 col-md-9"> <button class="btn btn-info" type="button" onclick="change_one_user_userinfo()"> <i class="ace-icon fa fa-check bigger-110"></i>立即修改</button>&nbsp; &nbsp; &nbsp;<button class="btn" type="reset"><i class="ace-icon fa fa-undo bigger-110"></i>重置</button></div></div></form></div>')
					});
				} else {
					alert("错误");
				}
			},
			error:function(rsultString){
				alert("错误");
			}
		});
		return false;
	} else if(permission==0){
		url="manager";
		$.ajax({
			type:"post",
			url:basePath+url+"/getbycondition",
			data:'{"id":"'+str+'"}',
			async:true,
			success:function(resultString){
				var result = eval(resultString);
				if(result.result_code==200){
					var resultList=new Array();
					resultList=eval(result.data.rows);
					$("#userInfos").empty();
					$.each(resultList, function (i, user) {
						$("#userInfos").append('<div id="change"> <form id="changeform" class="form-horizontal" role="form"> <input id="change_id_input" name="id" type="text" value="'+user.id+'" style="display:none;" /> <div class="form-group"> <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 编号：</label> <div class="col-sm-9"> <input readonly="" id="change_id" type="text" class="col-xs-10 col-sm-5" value="'+user.id+'" /> </div> </div> <input id="change_account_input" name="account" type="text" value="'+user.account+'" style="display:none;" /> <div class="form-group"> <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 账号：</label> <div class="col-sm-9"> <input readonly="" id="change_account" type="text" class="col-xs-10 col-sm-5" value="'+user.account+'" /> </div> </div> <div class="form-group"> <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 密码：</label> <div class="col-sm-9"> <input type="text" id="change_phone" name="password" value="'+user.password+'" placeholder="输入密码" class="col-xs-10 col-sm-5" /> </div> </div> <div class="form-group"> <label class="col-sm-3 control-label no-padding-right" for="form-field-1-1">姓名： </label> <div class="col-sm-9"> <input type="text" id="change_name" name="name" value="'+user.name+'" placeholder="输入姓名" class=" col-xs-10 col-sm-5" /> </div> </div> <div class="form-group"> <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 手机号：</label> <div class="col-sm-9"> <input type="text" id="change_phone" name="phone" value="'+user.phone+'" placeholder="输入手机号" class="col-xs-10 col-sm-5" /> </div> </div> <div class="form-group"> <label class="col-sm-3 control-label no-padding-right" for="form-field-1"> 邮箱：</label> <div class="col-sm-9"> <input type="text" id="change_mail" name="mail" value="'+user.mail+'" placeholder="输入邮箱" class="col-xs-10 col-sm-5" /> </div> </div> <div class="clearfix form-actions"> <div class="col-md-offset-3 col-md-9"> <button class="btn btn-info" type="button" onclick="change_one_manager_userinfo()"> <i class="ace-icon fa fa-check bigger-110"></i>立即修改</button>&nbsp; &nbsp; &nbsp;<button class="btn" type="reset"><i class="ace-icon fa fa-undo bigger-110"></i>重置</button></div></div></form></div>');
					});
				} else {
					alert("错误");
				}
			},
			error:function(rsultString){
				alert("错误");
			}
		});
		return false;
	}
}
function bookdayread(){
	var localObj = window.location;
	var contextPath = localObj.pathname.split("/")[1];
	var basePath = localObj.protocol+"//"+localObj.host+"/"+contextPath+"/";
	$.ajax({
		type:"post",
		url:basePath+"book/getbyreadamount",
		data:'{"key":"day"}',
		datatype:'JSON',
		async:true,
		success:function(resultString){
			var result = eval(resultString);
			if(result.result_code==200){
				book_search_table(result.data);
			} else {
				alert("错误");
			}
		},
		error:function(rsultString){
			var result = eval(resultString);
			if(result.result_code==200){
				book_search_table(result.data);
			} else {
				alert("错误");
			}
		}
	});
}
function bookmonthread(){
	var localObj = window.location;
	var contextPath = localObj.pathname.split("/")[1];
	var basePath = localObj.protocol+"//"+localObj.host+"/"+contextPath+"/";
	$.ajax({
		type:"post",
		url:basePath+"book/getbyreadamount",
		data:'{"key":"month"}',
		datatype:'JSON',
		async:true,
		success:function(resultString){
			var result = eval(resultString);
			if(result.result_code==200){
				book_search_table(result.data);
			} else {
				alert("错误");
			}
		},
		error:function(rsultString){
			var result = eval(resultString);
			if(result.result_code==200){
				book_search_table(result.data);
			} else {
				alert("错误");
			}
		}
	});
}
function bookyearread(){
	var localObj = window.location;
	var contextPath = localObj.pathname.split("/")[1];
	var basePath = localObj.protocol+"//"+localObj.host+"/"+contextPath+"/";
	$.ajax({
		type:"post",
		url:basePath+"book/getbyreadamount",
		data:'{"key":"year"}',
		datatype:'JSON',
		async:true,
		success:function(resultString){
			var result = eval(resultString);
			if(result.result_code==200){
				book_search_table(result.data);
			} else {
				alert("错误");
			}
		},
		error:function(rsultString){
			var result = eval(resultString);
			if(result.result_code==200){
				book_search_table(result.data);
			} else {
				alert("错误");
			}
		}
	});
}
function bookread(){
	var localObj = window.location;
	var contextPath = localObj.pathname.split("/")[1];
	var basePath = localObj.protocol+"//"+localObj.host+"/"+contextPath+"/";
	$.ajax({
		type:"post",
		url:basePath+"book/getbyreadamount",
		data:'{"key":"all"}',
		datatype:'JSON',
		async:true,
		success:function(resultString){
			var result = eval(resultString);
			if(result.result_code==200){
				book_search_table(result.data);
			} else {
				alert("错误");
			}
		},
		error:function(rsultString){
			var result = eval(resultString);
			if(result.result_code==200){
				book_search_table(result.data);
			} else {
				alert("错误");
			}
		}
	});
}
function get_section_menu(){
	var localObj = window.location;
	var contextPath = localObj.pathname.split("/")[1];
	var basePath = localObj.protocol+"//"+localObj.host+"/"+contextPath+"/";
	var id =getUrlParam("id");
	var sectionId =getUrlParam("sectionId");
	$.ajax({
		type:"post",
		url:basePath+"section/getbycondition",
		data:'{"bookId":"'+id+'"}',
		async:false,
		success:function(resultString){
			var result = eval(resultString);
			if(result.result_code==200){
				var sectionlist=new Array();
				sectionlist=eval(result.data.rows);
				$("#page").append('<ul class="pagination"></ul>');
				$.each(sectionlist, function (i, section) {
					if(i==0){
						if(sectionId==section.id){
							$(".pagination").append('<li class="disabled"><a href="http://120.78.199.110:8080/BookReading-1.0.0/html/bookdetail.html?id='+id+'&sectionId='+section.id+'">首页</a></li>');
						}else{
							$(".pagination").append('<li onclick="change_readinglog_section('+section.id+')"><a href="http://120.78.199.110:8080/BookReading-1.0.0/html/bookdetail.html?id='+id+'&sectionId='+section.id+'">首页</a></li>');
						}
					}else if(i==(sectionlist.length-1)){
						if(sectionId==section.id){
							$(".pagination").append('<li class="disabled"><a href="http://120.78.199.110:8080/BookReading-1.0.0/html/bookdetail.html?id='+id+'&sectionId='+section.id+'">尾页</a></li>');
						}else{
							$(".pagination").append('<li onclick="change_readinglog_section('+section.id+')"><a href="http://120.78.199.110:8080/BookReading-1.0.0/html/bookdetail.html?id='+id+'&sectionId='+section.id+'">尾页</a></li>');
						}
					}else{
						if(sectionId==section.id){
							$(".pagination").append('<li class="disabled"><a href="http://120.78.199.110:8080/BookReading-1.0.0/html/bookdetail.html?id='+id+'&sectionId='+section.id+'">第'+(i+1)+'页</a></li>');
						}else{
							$(".pagination").append('<li onclick="change_readinglog_section('+section.id+')"><a href="http://120.78.199.110:8080/BookReading-1.0.0/html/bookdetail.html?id='+id+'&sectionId='+section.id+'">第'+(i+1)+'页</a></li>');
						}
						
					}	
				});
			}
		}
	});
}
function change_readinglog_section(sectionId){
	var localObj = window.location;
	var contextPath = localObj.pathname.split("/")[1];
	var basePath = localObj.protocol+"//"+localObj.host+"/"+contextPath+"/";
	var id =getUrlParam("id");
	var section = new Object();
	section.id=sectionId;
	$.ajax({
		type:"post",
		url:basePath+"readingLog/changeradinglogsection",
		data:'{"bookId":"'+id+'","peruserId":"'+$.cookie('id')+'","sectionId":"'+section.id+'"}',
		async:false,
		success:function(resultString){

		}
	});
}
function add_one_book_comment(){
	var localObj = window.location;
	var contextPath = localObj.pathname.split("/")[1];
	var basePath = localObj.protocol+"//"+localObj.host+"/"+contextPath+"/";
	$.ajax({
		type:"post",
		url:basePath+"comment/add",
		data:JSON.stringify($("#addform").serializeObject()),
		async:true,
		success:function(resultString){
			var result = eval(resultString);
			if(result.result_code==200){
				window.location.href=basePath+"html/bookcomment.html?bookId="+$("#bookId").val();
			} else {
				alert("错误");
			}
		},
		error:function(rsultString){
			alert("错误");
			window.location.href=basePath+"html/bookcomment.html?bookId="+$("#bookId").val();
		}
	});
	return false;
}
function change_one_section(){
	var localObj = window.location;
	var contextPath = localObj.pathname.split("/")[1];
	var basePath = localObj.protocol+"//"+localObj.host+"/"+contextPath+"/";
	$.ajax({
		type:"post",
		url:basePath+"section/change",
		data:JSON.stringify($("#changeform").serializeObject()),
		async:true,
		success:function(resultString){
			var result = eval("("+resultString+")");
			if(result.result_code==200){
				window.location.href=basePath+"html/section.html";
			} else {
				alert("错误");
			}
		},
		error:function(rsultString){
			alert("错误");
			window.location.href=basePath+"html/section.html";
		}
	});
	return false;
}